package com.ws.user.user.service.impl;

import com.ws.common.easyui.util.Page;
import com.github.pagehelper.PageHelper;
import com.ws.user.user.dao.UserMapper;
import com.ws.user.user.service.IUserService;
import com.ws.user.user.entity.User;
import com.ws.common.base.service.Impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class UserServiceImpl extends BaseServiceImpl<User> implements IUserService {

	@Autowired
	UserMapper userMapper;

	@Override
	public List<User> list(User params) {
		return userMapper.list(params);
	}

	@Override
	public List<User> list(User params, Page page) {
		PageHelper.startPage(page.getPage(),page.getRows(),page.getSortOrder());
		return userMapper.list(params);
	}

	@Override
	public Integer save(User user) {
		user.setSearchName(user.getUserName()+user.getRealName());
		return this.insertOrUpdate(user);
	}

	@Override
	public User readByUserName(String userName) {
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("userName",userName);
		List<User> users=this.listByMap(map);
		if(users.size()==0){
			return null;
		}
		return users.get(0);
	}

	@Override
	public List<User> listByRoleId(String roleId, Page page) {
		PageHelper.startPage(page.getPage(),page.getRows(),page.getSortOrder());
		return userMapper.listByRoleId(roleId);
	}
}
